package com.yyjj.zixun.fragmnet;

import android.os.Bundle;
import android.view.View;

import com.aries.ui.view.title.TitleBarView;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.vise.xsnow.http.ViseHttp;
import com.vise.xsnow.http.callback.ACallback;
import com.vise.xsnow.http.mode.CacheMode;
import com.yyjj.zixun.R;
import com.yyjj.zixun.adapter.NeteaseAdapter;
import com.yyjj.zixun.api.Api;
import com.yyjj.zixun.entity.BiTeBiNewsEntity;

import java.util.ArrayList;

import tech.com.commoncore.app.FastManager;
import tech.com.commoncore.base.BaseTitleRefreshLoadFragment;
import tech.com.commoncore.constant.ApiConstant;
import tech.com.commoncore.entity.BaseTResp;


public class HomeZixunFragment extends BaseTitleRefreshLoadFragment<BiTeBiNewsEntity> {

    public static HomeZixunFragment newInstance() {
        Bundle args = new Bundle();
        HomeZixunFragment fragment = new HomeZixunFragment();
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void setTitleBar(TitleBarView titleBar) {
        titleBar.setVisibility(View.GONE);
//        getResources().getString(R.string.zixun_app_name)
    }

    @Override
    public int getContentLayout() {
        return R.layout.home_zixun_fragment;
    }

    @Override
    public void initView(Bundle savedInstanceState) {
        getData();

    }

    private void getData() {
        ViseHttp.GET(Api.NETEASE_URL)
                .baseUrl(ApiConstant.BASE_URL)
                .addParam("type", "4")
                .setHttpCache(true)
                .cacheMode(CacheMode.FIRST_REMOTE)
                .request(new ACallback<BaseTResp<ArrayList<BiTeBiNewsEntity>>>() {
                    @Override
                    public void onSuccess(BaseTResp<ArrayList<BiTeBiNewsEntity>> data) {
                        if (data.code == 1 && data.data != null) {
                            if (data.data.size()>=5){
                                FastManager.getInstance().getHttpRequestControl().httpRequestSuccess(getIHttpRequestControl(), data.data.subList(0,5), null);
                            }else {
                                FastManager.getInstance().getHttpRequestControl().httpRequestSuccess(getIHttpRequestControl(), data.data, null);
                            }

                        } else {
                            FastManager.getInstance().getHttpRequestControl().httpRequestSuccess(getIHttpRequestControl(), null, null);
                        }

                    }

                    @Override
                    public void onFail(int errCode, String errMsg) {
//                        FastManager.getInstance().getHttpRequestControl().httpRequestSuccess(getIHttpRequestControl(), null, null);
                    }
                });
    }

    @Override
    public BaseQuickAdapter<BiTeBiNewsEntity, BaseViewHolder> getAdapter() {
        return new NeteaseAdapter();
    }

    @Override
    public void loadData(int page) {

    }

    @Override
    public boolean isRefreshEnable() {
        return false;
    }

    @Override
    public boolean isLoadMoreEnable() {
        return false;
    }
}
